package DBase.Ships;

import DBase.Coordinate;


/**
 * 
 * @author Elya & Dana
 */
public class Ship {
    
    /**
     * invalid input
     */
    public static final int INVALID = -1;
    /**
     * way of ship placement
     */
    public static final int HORIZONTAL = 1;
    /**
     * way of ship placement
     */
    public static final int VERTICAL = 2;
    
    private int sizeOfShip;
    private int wayOfPlacement;
    private Coordinate  frontOfShip; //coordinate for the front of ship
    private Coordinate  backOfShip; //coordinate for the back of ship
    private boolean isActive;
    private String shipName;
    private int ShipActiveParts;
    
    /**
     * Ship Constructor
     * @param frontOfShip
     * @param sizeOfShip
     * @param shipName
     * @param wayOfPlacement Ship.Horizontal or Ship.Vertical
     */
    public Ship(Coordinate frontOfShip,int sizeOfShip,String shipName,int wayOfPlacement){
       
        this.frontOfShip = frontOfShip;
        this.sizeOfShip = sizeOfShip;
        this.shipName = shipName;
        this.wayOfPlacement=wayOfPlacement;
        
        ShipActiveParts = sizeOfShip;
        backOfShip = calculateBackCoordinate();
        isActive = true;
    }

     /**
     *Calculates the ships back coordinate(the end of the ship) 
     * @return Coordinate backship
     */
    private Coordinate calculateBackCoordinate(){
        
        Coordinate backCoordinate=new Coordinate(frontOfShip.getRow(),frontOfShip.getColumn());
        
        if (wayOfPlacement==HORIZONTAL)
            backCoordinate.setRow(backCoordinate.getRow()+sizeOfShip);
            
        else if (wayOfPlacement==VERTICAL)
            backCoordinate.setColumn(backCoordinate.getColumn()+sizeOfShip);
       
        return backCoordinate;
    }
    
    /**
     * Get coordinate of the back of a ship
     * @return Coordinate
     */
    public Coordinate getBackOfShip() {
        return backOfShip;
    }
    
    /**
     * Set coordinate of the back of a ship
     * @param BackOfShip coordinate
     */
    public void setBackOfShip(Coordinate BackOfShip) {
        this.backOfShip = BackOfShip;
    }

    /**
     * Gets coordinate of the front of a ship
     * @return frontOfShip coordinate
     */
    public Coordinate getFrontOfShip() {
        return frontOfShip;
    }

    /**
     * Sets the coordinate of the front of a ship
     * @param frontOfShip coordinate
     */
    public void setFrontOfShip(Coordinate frontOfShip) {
        this.frontOfShip = frontOfShip;
    }
  
    /**
     * Gets the size the ship
     * @return sizeOfShip
     */
    public int getSizeOfShip() {
        return sizeOfShip;
    }

    /**
     * Sets the size of the ship
     * @param sizeOfShip
     */
    public void setSizeOfShip(int sizeOfShip) {
        this.sizeOfShip = sizeOfShip;
    }  
    
    /**
     * Set ship to be active or inactive
     * @param IsActive true if active, false if inactive
     */
    public void setIsActive(boolean IsActive) {
        this.isActive = IsActive;
    }

    /**
     * Get way of ship placement
     * @return wayOfPlacement-Horizontal or Vertical
     */
    public int getWayOfPlacement() {
        return wayOfPlacement;
    }

    /**
     * Set way of ship placement
     * @param wayOfPlacement Horizontal or Vertical
     */
    public void setWayOfPlacement(int wayOfPlacement) {
        this.wayOfPlacement = wayOfPlacement;
    }
    /**
     * Set ship name
     * @param shipName
     */
    public void setShipName(String shipName) {
        this.shipName = shipName;
    }

    /**
     * Get ship name
     * @return shipName
     */
    public String getShipName() {
        return shipName;
    }
    /**
     * Get how many coordinates are active for a ship
     * @return shipActiveParts
     */
    public int getShipActiveParts() {
        return ShipActiveParts;
    }

    /**
     * Set how many coordinates are active for a ship
     * @param ShipActiveParts
     */
    public void setShipActiveParts(int ShipActiveParts) {
        this.ShipActiveParts = ShipActiveParts;
    }
    
}
